package com.sync.syncmasterdata;


import com.fasterxml.jackson.databind.ObjectMapper;
import com.sync.syncmasterdata.configuration.ConfInfo;
import com.sync.syncmasterdata.customer.service.http.HttpAPIServiceForCrmSync;
import com.sync.syncmasterdata.dingrobot.service.DingAPIService;
import com.sync.syncmasterdata.dingrobot.service.DingRobotService;
import com.sync.syncmasterdata.product.controller.ProductController;
import com.sync.syncmasterdata.product.entity.oa.ProductWorkflowUpdateEntity;
import com.sync.syncmasterdata.product.entity.u8.InvEx;
import com.sync.syncmasterdata.product.pojo.erp.InventoryForU8;
import com.sync.syncmasterdata.product.pojo.oa.InventoryForOA;
import com.sync.syncmasterdata.product.service.SyncInventoryService;
import com.sync.syncmasterdata.product.service.convert.ProductOAToU8;
import com.sync.syncmasterdata.util.AuthUtil;
import com.sync.syncmasterdata.vendor.repository.u8rep.U8VendoRepository;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.*;

/**
 * 产品 同步测试
 */
@SpringBootTest
@Slf4j
class SyncMasterDataApplicationTestForProduct {

    //钉钉服务
    @Autowired
    private DingRobotService dingRobotService;
    @Autowired
    private DingAPIService dingAPIService;
    @Autowired
    private ObjectMapper objectMapper;

    @Autowired
    private SyncInventoryService syncInventoryService;
    @Autowired
    private ProductController productController;

    @Autowired
    private ProductOAToU8 productOaToU8Service;

    @Autowired
    private U8VendoRepository u8VendoRepository;

    @Test
    void contextLoads() {
    }

    /**
     * 获取编辑对象
     */
    @Test
    public void editForTest() {
        Map<String, Object> map = new HashMap<>();
        map.put("requestid","473599");
        map.put("prod", "0");
        Map<String,Object> retMap=productController.productSourceOaByRequestid(map);
        System.out.println(retMap.toString());
    }

    /**
     * 170帐套推送测试
     */
    @Test
    public void to170ErpOrg() {
        String org = "3";
        InventoryForOA oaEntity = new InventoryForOA();
        oaEntity.setTongyongmc("JC0400001磁性微球");
        oaEntity.setKuwei("检测项目库");
        oaEntity.setChanpinlx("JC04");
        oaEntity.setCunhuobm("JC0400001");
        oaEntity.setChanpinmc("测试用的新类型");
        oaEntity.setHuohao("无");
        oaEntity.setGuigexh("人份");
        oaEntity.setZhujildw("006");
        oaEntity.setPinpaiwb("博圣");
        oaEntity.setShengchanqy(null);
        oaEntity.setShengchanqywb(null);
        oaEntity.setGuochanjk(0);
        oaEntity.setBeizhu("测试用的产品信息");
        oaEntity.setUnitName("份");
        oaEntity.setShifouylqx(0);


        //转换
        InventoryForU8 entity = productOaToU8Service.convertTo(oaEntity);
        String ret=syncInventoryService.addInvToOpenU8(entity,org);
        System.out.println("新增170返回："+ret);
    }

    @Test
    public void extestFor170() {
        InvEx ex = new InvEx();
        ex.setCidefine6("forTest");
        ex.setCInvCode("jc003test");
        syncInventoryService.addInvExFor170(ex);
    }

    @Test
    public void dingMsg() {
        List<String> userId=dingAPIService.convertPhoneToUseridList(Arrays.asList("15903019297"));
        this.dingRobotService.robotSendSampleMsg(sendDingMsg("测试"), userId);
    }

    private Map<String, String> sendDingMsg(String content) {
        Map<String, String> map = new HashMap<>();
        map.put("content", content);
        return map;
    }

    @Test
    public void testOfferProduct() {
        String code = "RJ010102";
        String ret = syncInventoryService.delInvToCPOfferProduct(code);
        System.out.println("--------->>>>>>ret>>>>>" + ret);
    }
}
